package com.bawei.shopping2

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import android.widget.Toast
import androidx.activity.viewModels
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.shopping.fragment.FourFragment
import com.bawei.shopping.fragment.OneFragment
import com.bawei.shopping.fragment.ThreeFragment
import com.bawei.shopping.fragment.TwoFragment
import com.bawei.shopping2.adapter.MyFragmentPagerAdapter
import com.bawei.shopping2.databinding.ActivityMainBinding
import com.bawei.shopping2.entity.BannerEntity
import com.bawei.shopping2.http.ApiResponse
import com.bawei.shopping2.utils.ArouterPath
import com.bawei.shopping2.utils.GlideUtils
import com.bawei.shopping2.viewmodel.MainViewModel
import com.bawei.shopping2.widget.BottomNavigationBar
import com.youth.banner.BannerConfig
import com.youth.banner.Transformer
import com.youth.banner.loader.ImageLoader
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
//注意：依赖注入
@Route(path = ArouterPath.ROUTE_MAIN_PATH)
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
    private lateinit var activityMainBinding: ActivityMainBinding
    private var list:MutableList<Fragment> = mutableListOf()
    private lateinit var  myFragmentPagerAdapter: MyFragmentPagerAdapter


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        activityMainBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(activityMainBinding.root)
        //viewpager
        list.add(OneFragment())
        list.add(TwoFragment())
        list.add(ThreeFragment())
        list.add(FourFragment())
        myFragmentPagerAdapter = MyFragmentPagerAdapter(list,FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT,supportFragmentManager)
        activityMainBinding.viewPager.adapter = myFragmentPagerAdapter
        //上下联动
        activityMainBinding.viewPager.addOnPageChangeListener(object :ViewPager.OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }

            override fun onPageSelected(position: Int) {
               activityMainBinding.bottom.setCurrentPage(position)
            }

            override fun onPageScrollStateChanged(state: Int) {

            }

        })
        activityMainBinding.bottom.setOnListener(object :
            BottomNavigationBar.onBottomNavClickListener {
            override fun onIconClick(viewId: Int, i: Int) {
                activityMainBinding.viewPager.currentItem = i
            }

            override fun onCenterIconClick() {
                Toast.makeText(this@MainActivity,"点击了中间",Toast.LENGTH_LONG).show()
            }

        })



    }



}